<template>
    <button id="show-modal" @click="showModal = !showModal">Show Modal</button>
    <transition name="modal">
        <div v-if="showModal">
            <div class="modal-mask">
                <div class="modal-wrapper">
                    <div class="modal-container">
                        <div class="closeModal" @click="showModal = !showModal"></div>
                        <slot></slot>
                    </div>
                </div>
            </div>
        </div>
    </transition>
</template>

<script>
export default {
    props: {
        width: {
            type: String,
            default: "90vw"
        },
        maxWidth: {
            type: String,
            default: "600px"
        },
    },
    data() {
        return {
            showModal: false
        }
    },
}
</script>

<style lang="scss" scoped>
.modal-mask {
    position: fixed;
    z-index: 9998;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: table;
    transition: opacity 0.3s ease;
}

.modal-wrapper {
    display: table-cell;
    vertical-align: middle;
}

.modal-container {
    position: relative;
    width: 300px;
    margin: 0px auto;
    padding: 20px 30px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
    transition: all 0.3s ease;
}


.modal-default-button {
    float: right;
}

.closeModal {
    position: absolute;
    float: right;
    top: 16px;
    right: 16px;
    width: 24px;
    height: 24px;
    opacity: 0.2;
    cursor: pointer;
    transition: opacity ease 0.5s;

    &:hover {
        opacity: .8;
    }
}

.closeModal::before,
.closeModal::after {
    content: '';
    position: absolute;
    top: 10px;
    display: block;
    width: 20px;
    height: 2px;
    background: #000;
}

.closeModal::before {
    transform: rotate(45deg);
}

.closeModal::after {
    transform: rotate(-45deg);
}

.modal-enter-from,
.modal-leave-to {
    opacity: 0;
}

.modal-enter-active .modal-container,
.modal-leave-active .modal-container {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}
</style>